import React, { Component } from 'react';
import {goodsList} from '../request/goodslist'
import qs from 'qs'
import {NavLink} from 'react-router-dom'
class Goodslist extends Component {
    state = {
        getGoodsList:[],
        id:0
    }
    UNSAFE_componentWillMount()
    {
        this.setState({id:qs.parse(this.props.location.search.substr(1))});
        goodsList(this.state.id.id).then(res=>{
            if(res.code === 200)
            {
                this.setState({getGoodsList:res.list})
            }
        })
    }
    render() {
        let {getGoodsList} = this.state
        return (
            <>
                <div className="page-title">商品列表</div>
                {/* <!-- 商品列表 --> */}
                <div className="goodslist">
                {
                    getGoodsList.map(item=>{
                        return <div className="item" key={item.id}>
                            <img src={this.$staticUrl + item.img} alt="" />
                            <div>
                                <h5><NavLink to={"/goodsdetail?id="+item.id}>{item.goodsname}</NavLink></h5>
                                <p className="price">&yen;{item.price}</p>
                                <p className="market-price">&yen;{item.market_price}</p>
                                <button className="btn-cart">加入购物车</button>
                            </div>
                        </div>
                    })
                }
                 </div>
            </>
        );
    }
}

export default Goodslist;